package vip.specimen.system.datasource.validation.implement;

import vip.specimen.system.datasource.entity.SystemArticleCategoriesEntity;
import vip.specimen.system.datasource.validation.annotation.Categories;
import vip.specimen.system.service.SystemArticleCategoriesService;

import javax.annotation.Resource;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.List;
import java.util.Set;
import java.util.UUID;

/**
 * *@Author: 余浪人
 * *@Date：2021/4/12 10:12
 * *@Email:yulangren520@Gmail.com
 * *@QQ:1368419640
 **/
public class CategoriesImp implements ConstraintValidator<Categories, Set<UUID>> {

    @Resource
    private SystemArticleCategoriesService categoriesService;

    @Override
    public boolean isValid(Set<UUID> uuidList, ConstraintValidatorContext constraintValidatorContext) {
        if (null == uuidList || uuidList.size() == 0) return false;
        List<SystemArticleCategoriesEntity> list = this.categoriesService.findAllById(uuidList);
        return(uuidList.size() == list.size()) && !list.contains(null);
    }
}
